﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Web;
using System.Web.Mvc;
using System.Web.Script.Serialization;
using System.Text;

using RenrenDotSDK;
using RenrenDotSDK.Model;

namespace iSufeMVC4.Areas.Social.Controllers
{
    public class RenrenController : Controller
    {
        //
        // GET: /Social/Renren/
        RenrenApiClient rr = new RenrenApiClient();

        public ActionResult Index()
        {
            rr.GetAuthorizationCode();
            return View();
        }

        public ActionResult Home()
        {
            ViewBag.Message = GetFriend();
            return View();
        }


        protected string GetFriend()
        {
            if (Request["code"] == null)
                return "";
            string responseData = rr.CallMethod("friends.getFriends");
            List<Friend> list = new JavaScriptSerializer().Deserialize<List<Friend>>(responseData);
            StringBuilder sbList = new StringBuilder();
            foreach (Friend f in list)
            {
                sbList.AppendFormat("<li>{0}<br />{1}<br /><img src='{2}' alt='{2}' /></li>", f.Id, f.Name, f.Tinyurl);
            }
            return sbList.ToString();
        }

    }
}
